import LevelTemplate from "./LevelTemplate";

export default class LevelManager implements IModelManager {

    private static _single: LevelManager = null;
    private levelMap: Map<number, LevelTemplate>;
    public static get single(): LevelManager {
        if (LevelManager._single == null) {
            LevelManager._single = new LevelManager();
        }
        return LevelManager._single;
    }

    initConfig(): void {
        this.levelMap = new Map();

        var levelJson = cc.resources.get("configs/level", cc.JsonAsset);
        for (const iterator of levelJson.json) {
            var levelTp = new LevelTemplate();
            levelTp.init(iterator);
            this.levelMap.set(levelTp.level, levelTp);
        }
    }

    getLevelTemplate(lv: number): LevelTemplate {
        return this.levelMap.get(lv);
    }


}
